package com.greatwqs.wmall.product.provider.controller;

import com.greatwqs.wmall.common.module.model.LoginUser;
import com.greatwqs.wmall.common.module.util.JsonUtil;
import com.greatwqs.wmall.product.provider.model.vo.ProductInfoVo;
import com.greatwqs.wmall.product.provider.service.ProductService;
import lombok.extern.slf4j.Slf4j;

import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wang-qingsong
 */
@Slf4j
@RestController
@RequestMapping(value = "/api/wmall/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping(value = "info/{productId}")
    public ProductInfoVo getProductInfo(
            LoginUser loginUser,
            @PathVariable("productId") Long productId) {
        log.info("getProductInfo traceId：{}, productId: {}", TraceContext.traceId(), JsonUtil.toJson(productId));
        return productService.getProductInfo(productId);
    }

    @GetMapping(value = "rate-limit-test")
    public ProductInfoVo rateLimitTest() {
        log.info("rateLimitTest traceId：{}", TraceContext.traceId());
        return productService.getProductInfo(1L);
    }
}